@extends('admin.base')
@section('title','公告列表')
@section('header','公告列表')
@section('content')

    <fieldset class="layui-elem-field">
        <div class="layui-field-box">
            <span class="layui-breadcrumb" lay-separator=">>">
                <a class="layui-btn-sm" href="{{url('admin/notice/index')}}" style="cursor:pointer;" ><cite>公告列表</cite></a>;
            </span>
        </div>
    </fieldset>
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <form method="get">
                    <div class="layui-card-header ">
                        <div class="layui-form " style="display: flex;">
                            <p class="">关键字：</p>
                            <!--搜索框-->
                            <div class="layui-inline sousuo">
                                <div class="layui-input-inline">
                                    <input type="text" name="title" class="layui-input" id="" placeholder="请输入标题"
                                           value="{{$request->keywords}}">
                                </div>
                            </div>
                            <button type="submit" class="layui-btn ok" style="margin-top:4px">确定</button>
                        </div>
                    </div>
                </form>
                <div class="layui-card-body">
                    <p style="float: left;margin-bottom: 20px">
                        <a href="/admin/notice/create" class="layui-btn layui-btn-success layui-btn">添加公告</a>
                    </p>
                    <table class="layui-table">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>标题</th>
                            <th>状态</th>
                            <th>排序</th>
                            <th>创建时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        @forelse($news as $vo)
                            <tr>
                                <td>{{$vo->id}}</td>
                                <td>{{$vo->title}}</td>
                                <td>
                                    @if($vo->state==1)
                                        <a href="#" onclick="change_state('{{$vo->id}}',2,'确认隐藏吗?')"
                                           class="layui-btn layui-btn-success layui-btn-sm">显示</a>
                                    @else
                                        <a href="#" onclick="change_state('{{$vo->id}}',1,'确认显示吗?')"
                                           class="layui-btn layui-btn-danger layui-btn-sm">隐藏</a>
                                    @endif
                                </td>
                                <td><a href="javascript:void(0);"
                                       onclick="sorts({{$vo->id}},{{$vo->sort}})">{{$vo->sort}}</a></td>
                                <td>{{$vo->created_at}}</td>
                                <td>
                                    <a href="/admin/notice/edit?id={{$vo->id}}"
                                       class="layui-btn layui-btn-sm">修改</a>
                                    <a href="#" onclick="del_cy('{{$vo->id}}','确认删除吗?')"
                                       class="layui-btn layui-btn-sm layui-btn-danger">删除</a>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="11" style="text-align:center">暂无内容</td>
                            </tr>
                        @endforelse
                        </tbody>
                    </table>
                    {{$news->appends(Request::all())->links()}}
                </div>
            </div>
        </div>
    </div>
@endsection
@section('js')
    <script>
        layui.use('element', function () {
            var element = layui.element;
        });

        function change_state(id, value, msg) {
            event.preventDefault();
            layer.confirm(msg, {
                btn: ['确认', '取消'] //按钮
            }, function () {
                window.location.href = '/admin/notice/change_state?id=' + id + '&value=' + value;

            })
        }

        function del_cy(id, msg) {
            event.preventDefault();
            layer.confirm(msg, {
                btn: ['确认', '取消'] //按钮
            }, function () {
                window.location.href = '/admin/notice/del?id=' + id ;

            })
        }

        function sorts(id, num) {
            layer.prompt({
                formType: 3,
                value: num,
                title: '修改排序'
            }, function (value, index, elem) {
                var index = layer.load();
                $.post("/admin/notice/update_sort", {
                    id: id,
                    sort: value,
                    _token: "{{csrf_token()}}"
                }, function (data) {
                    layer.close(index);
                    layer.msg(data.msg);
                    if (data.code == 1) {
                        location.reload();
                    }

                })
            });
        }

    </script>
@endsection
